﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace JGSY.WinAlarmManage
{
    /// <summary>
    /// 
    /// </summary>
    public partial class FrmRecord : Form
    {
        /// <summary>
        /// 
        /// </summary>
        public FrmRecord()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 
        /// </summary>
        private void CommonClass_UpdateAlarmLogList()
        {
            dgvAlarm.SafeInvoke(new Action(() =>
            {
                //刷新列表页----重新绑定一下
                UpdageDgvDataSource();
            }));
        }
        /// <summary>
        /// 
        /// </summary>
        private void FrmRecord_Load(object sender, EventArgs e)
        {
            dgvAlarm.AutoGenerateColumns = false;
            CommonClass.UpdateAlarmLogList += CommonClass_UpdateAlarmLogList;
            //UpdageDgvDataSource();
            // 安全更新 UI
            if (this.IsHandleCreated)
            {
                this.SafeInvoke(() => UpdageDgvDataSource());
            }
            else
            {
                // 如果句柄还没创建，等待创建后再执行
                this.HandleCreated += (s, args) => this.SafeInvoke(() => UpdageDgvDataSource());
            }
        }
        /// <summary>
        /// 绑定预警记录列表到dgv中
        /// </summary>
        private void UpdageDgvDataSource()
        {
            dgvAlarm.DataSource = null;
            if (CommonClass.logList.Count > 0)
                dgvAlarm.DataSource = CommonClass.logList;
        }
    }
}
